import {
        getHomeSwiperData,
        getNavigation,
        getSecond,
        getproducts,
        getproduct,
        getbargaining,
        getwork
} from '../../netWork/api/apihome.js';
const WXAPI = require('apifm-wxapi')
WXAPI.init('anxiaodong')
Page({
        /**
         * 页面的初始数据
         */
        data: {
                title: [],
                list: [], //轮播图数据
                date: [], //导航数据
                lzh: [], //优惠资讯数据
                second: [], //限时秒杀数据
                products: [], //爆款推荐
                bargaining: [], //疯狂砍价
                work: [], //全民拼团
                product: [], //商品列表
                purchase: [] //获取购买过的商品列表
        },
        search(){
                wx.navigateTo({
                        url:'/pages/search/search'
                })
        },

        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {
                // 轮播图
                getHomeSwiperData().then(res => {
                        this.setData({
                                list: res.data.data.splice(3, 3)
                        })
                        // 导航
                        getNavigation().then(res => {
                                this.setData({
                                        date: res.data.data
                                })
                        })

                        // 优惠资讯
                        WXAPI.noticeList().then(res => {
                                this.setData({
                                        lzh: res.data.dataList
                                })
                        })

                        // 限时秒杀
                        getSecond().then(res => {
                                this.setData({
                                        second: res.data.data
                                })
                        })

                        // 爆品推荐
                        getproducts().then(res => {
                                this.setData({
                                        products: res.data.data.splice(12, 2)
                                })
                        })

                        // 疯狂砍价
                        getbargaining().then(res => {
                                this.setData({
                                        bargaining: res.data.data
                                })
                        })

                        // 全民拼团
                        getwork().then(res => {
                                this.setData({
                                        work: res.data.data
                                })
                        })

                        // 商品列表
                        getproduct().then(res => {
                                this.setData({
                                        product: res.data.data
                                })
                        })
                })
        },
        onShow: function () {
                // 优惠资讯
                WXAPI.noticeList().then(res => {
                        this.setData({
                                lzh: res.data.dataList
                        })
                })
        },

        // 导航  点击跳转到分类页面
        navigators(e) {
                let id = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/classify/classify?id=' + id,
                })
        },

        // 限时秒杀
        second(e) {
                let id = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/second/second?id=' + id,
                })
        },

        // 爆品推荐
        products(e) {
                let product = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/goodsDetail/goodsDetail?products=' + product,
                })
        },

        // 疯狂砍价
        bargaining(e) {
                let product = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/goodsDetail/goodsDetail?bargaining=' + product,
                })
        },

        // 全民拼团
        work(e) {
                let product = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/goodsDetail/goodsDetail?work=' + product,
                })
        },

        // 商品列表
        product(e) {
                let product = e.currentTarget.dataset.id
                wx.reLaunch({
                        url: '/pages/goodsDetail/goodsDetail?product=' + product,
                })
        }
})